<html>
  <head>
    <script
      src="https://cdn.socket.io/4.3.2/socket.io.min.js"
      integrity="sha384-KAZ4DtjNhLChOB/hxXuKqhMLYvx3b5MlT55xPEiNmREKRzeEm+RVPlTnAn0ajQNs"
      crossorigin="anonymous"
    ></script>
    <script>
      const socket = io('http://localhost:3000');
      socket.on('connect', function () {
        console.log('Connected');

        socket.emit('findAllBook', (response) =>
          console.log('findAllBook', response),
        );

        socket.emit('findOneBook', 1, (response) =>
          console.log('findOneBook', response),
        );

        socket.emit('createBook', { name: 'guang' }, (response) =>
          console.log('createBook', response),
        );

        socket.emit('updateBook', { id: 2, name: 'dong' }, (response) =>
          console.log('updateBook', response),
        );

        socket.emit('removeBook', 2, (response) =>
          console.log('removeBook', response),
        );

        // 如果在服务端指定了 event  必须监听事件名才能接收到数据
        socket.on('lrq', function (data) {
          console.log('lrq', data);
        });
        socket.on('test-server', function (data) {
          console.log('test-server', data);
        });
      });
      socket.on('disconnect', function () {
        console.log('Disconnected');
      });
    </script>
  </head>

  <body></body>
</html>
